package com.freesky.biz.icbc.controller;

import com.freesky.biz.icbc.domain.TPartnership;
import com.freesky.biz.icbc.domain.TPensionUser;
import com.freesky.biz.icbc.service.IPartnershipService;
import com.freesky.biz.icbc.service.IPensionUserService;
import com.freesky.common.annotation.Log;
import com.freesky.common.annotation.RepeatSubmit;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import com.freesky.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 线下养老金领取
 */
@RestController
@RequestMapping("/icbc/pension")
public class PensionUserController extends BaseController {

    @Autowired
    private IPensionUserService pensionUserService;

    /**
     * 线下养老金领取
     */
    @PreAuthorize("@ss.hasPermi('icbc:pensionuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPensionUser pensionUser) {
        startPage();
        List<TPensionUser> list = pensionUserService.findList(pensionUser);
        return getDataTable(list);
    }

    @Log(title = "线下养老金", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('icbc:pensionuser:export')")
    @GetMapping("/export")
    public AjaxResult export(TPensionUser pensionUser,
                             HttpServletResponse response) {
        return pensionUserService.exportFile(pensionUser);
    }

    @PreAuthorize("@ss.hasPermi('icbc:pensionuser:import')")
    @RepeatSubmit
    @RequestMapping("/template")
    public void exportExcel() {
        pensionUserService.exportExcel();
    }


    @PreAuthorize("@ss.hasPermi('icbc:pensionuser:import')")
    @Log(title = "线下养老金", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @RequestMapping("/import")
    public AjaxResult importExcel(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            throw new CustomException("导入文件不能为空！");
        }
        return pensionUserService.importExcel(file);
    }

}
